<template>
    <div>
        <h1>新增房号</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="queryInfo.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in Typelist">{{ item.HouseTypeName }}
                            </option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td>房间号码</td>
                    <td>
                        <input type="text" v-model="queryInfo.HouseNumberName">
                    </td>
                </tr>

                <tr>
                    <td>房号描述</td>
                    <td>
                        <textarea cols="30" rows="5" v-model="queryInfo.Intro"></textarea>
                    </td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" :value="1" v-model="queryInfo.State" checked>上架
                        <input type="radio" name="state" :value="0" v-model="queryInfo.State">下架
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-info" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
import { useUserStore } from '@/stores/user'

const route = useRoute();
const router = useRouter();

const abc = useUserStore();

let queryInfo: any = reactive({
    "HouseTypeId": '',
    "HouseNumberName": "",
    "Intro": "",
    "State": 1,
    "Isdeleted": false
})

let Typelist: any = ref([])

onMounted(() => {
    getType()
})

const getType = () => {
    axios({
        url: '/api/HouseNumber/SelectHouseTypelist',
        method: 'get',
    })
        .then(res => {
            console.log(res);
            Typelist.value = res.data;
        })
        .catch(err => {
            console.log(err);

        })
}

const ok = () => {
    axios({
        url: '/api/HouseNumber/AddHouseNumber',
        method: 'post',
        data: queryInfo
    })
        .then(res => {
            console.log(res);
            if (res.data > 0) {
                alert('添加成功')
                router.push('/conShow')
            }
            else {
                alert('添加失败')
                return
            }
        })
        .catch(err => {
            console.log(err);

        })
}
</script>

<style scoped></style>